package cn.weakup.designpattern.d_behavior.strategy.usepattern;

import java.math.BigDecimal;

/**
 * @author lixj
 * @version 1.0.0
 * @date 2022/6/2
 * @desc 直减算法
 */
public class JustDiscountCouponDiscount implements ICouponDiscount<String>{
    /**
     * 直减⾦额计算
     *
     * @param couponInfo 直减金额
     * @param totalPrice 原商品总价
     * @return 优惠价
     */
    @Override
    public BigDecimal discountAmount(String couponInfo, BigDecimal totalPrice) {
        BigDecimal discount = new BigDecimal(couponInfo);
        if(totalPrice.compareTo(discount) < 0) {
            return BigDecimal.ONE;
        }
        return totalPrice.subtract(discount);
    }
}
